<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    Number.prototype.toFixed = function (d) {
        var s = this + '';
        if (!d) d = 0;
        if (s.indexOf('.') == -1) s += '.';
        s += new Array(d + 1).join('0');
        if (new RegExp('^(-|\\+)?(\\d+(\\.\\d{0,' + (d + 1) + '})?)\\d*$').test(s)) {
            var s = '0' + RegExp.$2, pm = RegExp.$1, a = RegExp.$3.length, b = true;
            if (a == d + 2) {
                a = s.match(/\d/g);
                if (parseInt(a[a.length - 1]) > 4) {
                    for (var i = a.length - 2; i >= 0; i--) {
                        a[i] = parseInt(a[i]) + 1;
                        if (a[i] == 10) {
                            a[i] = 0;
                            b = i != 1;
                        } else {
                            break;
                        }
                    }
                }
                s = a.join('').replace(new RegExp('(\\d+)(\\d{' + d + '})\\d$'), '$1.$2');

            }
            if (b) s = s.substr(1);
            return (pm + s).replace(/\.$/, '');
        }
        return this + "";
    };
</script>
<script>
    window.onload = function () {
        // AVG_ABSOLUTE_ERROR_RATE: '',  平均绝对误差
        // RMSE: '', 均方根误差
        // ACCU_RATE: '', 准确率
        // PASS_RATE: '', 合格率
        // CORRELATION: '' 相关系数
        const cap = 50;

        const realData = [-0.0068, -0.0051, -0.0049, -0.0072, -0.0068, -0.0062, -0.0062, -0.0062, -0.0062, -0.0068, -0.0062, -0.0083, -0.0062, -0.0072, -0.0054, -0.0049, -0.0066, -0.0066, -0.0051, -0.0066, -0.0066, -0.0051, -0.0049, -0.0054, -0.0027, 0.1648, 0.9072, 3.8423, 7.4599, 11.1805, 14.8581, 18.6694, 21.6836, 25.9681, 31.0562, 34.6789, 36.9363, 41.2139, 41.3081, 47.4428, 46.0513, 51.3804, 49.0538, 47.6682, 53.6813, 51.9248, 51.238, 51.0868, 52.2756, 51.4408, 51.6376, 56.4214, 51.64, 51.8339, 48.6985, 47.2549, 46.3255, 44.3447, 39.0394, 34.0683, 28.5372, 27.326, 23.8889, 25.4653, 17.8652, 9.4711, 14.4427, 9.1772, 7.6221, 5.6118, 2.2353, 0.4441, 0.062, -0.0108, -0.0072, -0.0036, -0.0067, -0.0066, -0.0051, -0.0062, -0.0062, -0.0063, -0.0062, -0.0051, -0.0051, -0.0062, -0.0062, -0.0051, -0.0062, -0.0062, -0.0054, -0.0062, -0.0062, -0.0051, -0.0062, null]

        const facData = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6.528700, 12.619201, 27.859213, 40.290210, 55.085190, 70.031574, 85.311802, 100.743690, 114.623668, 132.042975, 144.533799, 160.095592, 173.328153, 188.434151, 204.759082, 214.525643, 230.416747, 237.984225, 247.401697, 252.045113, 242.080685, 246.378394, 246.636888, 248.493397, 242.083570, 236.853042, 231.483509, 223.047759, 219.760808, 223.372101, 220.245733, 209.016029, 196.744414, 183.191200, 171.307439, 157.017404, 137.554456, 112.139385, 97.567680, 67.420998, 59.149341, 48.886159, 44.154339, 36.022160, 28.545118, 18.128747, 11.281106, 2.305394, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]


        // 计算平均绝对误差 this.sload.AVG_ABSOLUTE_ERROR_RATE
        let AVG_ABSOLUTE_ERROR_RATE = 0;
        let A = 0;
        // 均方根误差
        let RMSE = 0;
        let B = 0;

        // 合格率
        let PASS_RATE = 0;
        let C = 0;

        // 计算相关系数
        let CORRELATION = 0;

        let ycAvg = 0;
        let realAvg = 0;

        let AB = 0;

        let D = 0;
        let E = 0;
        for (let i = 0; i < facData.length; i++) {
            ycAvg += facData[i] * 1
            realAvg += realData[i] * 1
        }
        ycAvg = (ycAvg / 96)
        realAvg = (realAvg / 96)


        for (let i = 0; i < facData.length; i++) {
            let fac = facData[i] * 1;
            let real = realData[i] * 1;
            let oneData = (Math.abs(fac - real)) / cap
            // 计算平均绝对误差
            A += oneData

            // 均方根误差
            let tmp = (fac - real) / cap
            B += tmp * tmp

            // 计算合格率
            C += oneData > 0.25 ? 0 : 1;

            // 计算相关系数
            AB += (fac - ycAvg) * (real - realAvg)
            D += (fac - ycAvg) * (fac - ycAvg)
            E += (real - realAvg) * (real - realAvg)

        }
        // 计算平均绝对误差 this.sload.AVG_ABSOLUTE_ERROR_RATE
        AVG_ABSOLUTE_ERROR_RATE = ((A / 96)).toFixed(2)
        console.log(AVG_ABSOLUTE_ERROR_RATE)

        // 均方根误差
        RMSE = Math.sqrt((B / 96)).toFixed(2)
        console.log(RMSE);

        // 准确率
        let ACCU_RATE = 0;
        ACCU_RATE = ((1 - RMSE)).toFixed(2)
        console.log(ACCU_RATE)

        // 合格率
        PASS_RATE = ((C / 96)).toFixed(2)
        console.log(PASS_RATE)


        D = Math.sqrt(D)
        E = Math.sqrt(E)
        CORRELATION = ((AB / D) / E).toFixed(2)
        console.log(CORRELATION)

    }

</script>
<script>
    let arrs = [1, 2, 3];
    let bbx = ['a', 'b', 'c'];
    arrs = [].concat(bbx);
    console.log(arrs)
    console.log(bbx)
    arrs[0] = 'jkl';
    console.log(arrs)
    console.log(bbx)
</script>

<script>
    let are=[];
    var fkrr = {
        "regionEntities": [
            {
                "id": "2010000000331000",
                "name": "台州市",
                "compId": null,
                "pid": "2010000000331000",
                "displayIdx": null,
                "code": "1",
                "parentAreaId": null,
                "remark": null,
                "domain": null,
                "longitude": null,
                "latitude": null,
                "regionEntities": [{
                    "id": "2010000000331002",
                    "name": "椒江区",
                    "compId": null,
                    "pid": "2010000000331000",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331003",
                    "name": "黄岩区",
                    "compId": null,
                    "pid": "2010000000331000",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331004",
                    "name": "路桥区",
                    "compId": null,
                    "pid": "2010000000331000",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331021",
                    "name": "玉环市",
                    "compId": null,
                    "pid": "2010000000331000",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331022",
                    "name": "三门县",
                    "compId": null,
                    "pid": "2010000000331000",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331023",
                    "name": "天台县",
                    "compId": null,
                    "pid": "2010000000331000",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331024",
                    "name": "仙居县",
                    "compId": null,
                    "pid": "2010000000331000",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331081",
                    "name": "温岭市",
                    "compId": null,
                    "pid": "2010000000331000",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331082",
                    "name": "临海市",
                    "compId": null,
                    "pid": "2010000000331000",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }]
            },
            {
                "id": "2010000000331100",
                "name": "丽水市",
                "compId": null,
                "pid": "2010000000331100",
                "displayIdx": null,
                "code": "1",
                "parentAreaId": null,
                "remark": null,
                "domain": null,
                "longitude": null,
                "latitude": null,
                "regionEntities": [{
                    "id": "2010000000331102",
                    "name": "莲都区",
                    "compId": null,
                    "pid": "2010000000331100",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331121",
                    "name": "青田县",
                    "compId": null,
                    "pid": "2010000000331100",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331122",
                    "name": "缙云县",
                    "compId": null,
                    "pid": "2010000000331100",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331123",
                    "name": "遂昌县",
                    "compId": null,
                    "pid": "2010000000331100",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331124",
                    "name": "松阳县",
                    "compId": null,
                    "pid": "2010000000331100",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331125",
                    "name": "云和县",
                    "compId": null,
                    "pid": "2010000000331100",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331126",
                    "name": "庆元县",
                    "compId": null,
                    "pid": "2010000000331100",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331127",
                    "name": "景宁畲族自治县",
                    "compId": null,
                    "pid": "2010000000331100",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }, {
                    "id": "2010000000331181",
                    "name": "龙泉市",
                    "compId": null,
                    "pid": "2010000000331100",
                    "displayIdx": null,
                    "code": "2",
                    "parentAreaId": null,
                    "remark": null,
                    "domain": null,
                    "longitude": null,
                    "latitude": null,
                    "regionEntities": null
                }]
            }]
    }

    function tree(data, id) {
        if (!(data.regionEntities)) {
           if (data.id === id){
              if (data.code == 2){
                  are=[].concat([data.pid,data.id])
                  console.log(are)
              }
           }
        } else {
            data.regionEntities.forEach(item => {
                tree(item, id)
            })
        }
    }

    tree(fkrr, "2010000000331003")
</script>
</html>
